/**
 * 文章接口模块
 */

import request from '@/utils/request.js'

/**
 * 封装频道的文章列表
 */
export const getArticles = params => {
  return request({
    method: 'GET',
    url: '/v1_0/articles',
    params
  })
}

/**
 * 获取文章详情
 */
export const getArticleById = ID => {
  return request({
    method: 'GET',
    url: `/v1_0/articles/${ID}`
  })
}

/**
 * 收藏
 * target:收藏的文章ID
 */
export const addCollection = target => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target
    }
  })
}

/**
 * 取消收藏
 * target:取消收藏文章的ID
 */
export const deleteCollection = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/collections/${target}`
  })
}

/**
 * 点赞
 * target:点赞的文章ID
 */
export const addLike = target => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target
    }
  })
}

/**
 * 取消点赞
 * target:取消点赞文章的ID
 */
export const deleteLike = target => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${target}`
  })
}
